<!DOCTYPE html>
<html lang="zh">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Document</title>
	<style>
		*{
			margin: 0;
			padding: 0;
		}
		body{
			background-color: #ddd;
		}
		.box{
			width: 600px;
			height: 500px;
			margin: 100px auto;
		}
		.box .nav1{
			width: 200px;
			float: right;
		}
		.box .nav1 p{
			height: 100px;
			background-color: #bfa;
		}
		.box .nav2{
			width: 400px;
			float: left;
		}
		.box .nav2 img{
			width: 100%;
			height: 100%;
			display: none;
		}
		.box .nav2 .one{
			display: block;
		}
	
	</style>
</head>
<body>
	<div class="box">
		<div class="nav1">
			<p>第一张</p>
			<p>第一张</p>
			<p>第一张</p>
			<p>第一张</p>
		</div>
		<div class="nav2">
			<img src="./img/nature-1.jpg" alt="" class="one">
			<img src="./img/nature-2.jpg" alt="" >
			<img src="./img/nature-3.jpg" alt="">
			<img src="./img/nature-5.jpg" alt="">
		</div>
		
	</div>
</body>
	<script>
		var p = document.getElementsByTagName('p');
		var img = document.getElementsByTagName('img');
		for(var i = 0; i < p.length; i++){
			p[i].onclick = function(){
				for(var i = 0; i < p.length; i++){
					p[i].style.background = "blue";
				}
				this.style.background = "red";
				for(var i = 0; i < img.length; i++){
					console.log(img);
					if(p[i] == this){
						p[i].classList.add('one');
						img[i].classList.add('one');
					}else{
						p[i].classList.remove('one');
						img[i].classList.remove('one');
					}
				}	
			}
		}
		
		
		
		
	</script>
</html>